package ua.kpi_java_training.zabrodskyi.module2;

/**
 * @author Maksym Zabrodskyi
 * @version 10-Jun-2013
 */
public class Statistics {

    private static int numberRuinedVictims = 0;
    private static int numberSpawnedVictims = 0;
    private Pool pool;
    private int numberFishes = 0;
    private int numberPredators = 0;
    private int numberVictims = 0;
    private int lengthLife = 0;
    private double percentFishes = 0;

    public Statistics(Pool pool) {
        this.pool = pool;
    }

    public static void countRuinedVictim() {
        numberRuinedVictims++;
    }

    public static void countSpawnedVictim() {
        numberSpawnedVictims++;
    }

    public void saveFirstParameters(Initialization settings) {
        numberFishes = pool.getNumberObjects(new Fish());
        numberPredators = settings.getNumberPredators();
        numberVictims = settings.getNumberVictims();
        lengthLife = settings.getLengthLife();
    }

    public void calculateLastParameters() {
        numberFishes = pool.getNumberObjects(new Fish());
        numberPredators = pool.getNumberObjects(new Predator());
        numberVictims = pool.getNumberObjects(new Victim());
        percentFishes = numberFishes * 100.0 / pool.getSize();
    }

    public void printFirstStatistics() {
        Printer.printToConsole("* * * * *  Life in Pool  * * * * *");
        Printer.printToConsole(pool.toString());
        Printer.printToConsole("The first numbers of all Fishes = ",
                numberFishes);
        Printer.printToConsole("The first numbers of Predators = ",
                numberPredators);
        Printer.printToConsole("The first numbers of Victims = ", numberVictims);
        Printer.printToConsole("Life goes ", lengthLife, " times");
    }

    public void printLastStatistics() {
        Printer.printToConsole("* * * * *  Results  * * * * *");
        Printer.printToConsole(pool.toString());
        Printer.printToConsole("The last numbers of all Fishes = ",
                numberFishes);
        Printer.printToConsole("The last numbers of Predators = ",
                numberPredators);
        Printer.printToConsole("The last numbers of Victims = ", numberVictims);
        Printer.printToConsole("Numbers of ruined Victims = ",
                numberRuinedVictims);
        Printer.printToConsole("Numbers of spawned Victims = ",
                numberSpawnedVictims);
        Printer.printToConsole("The Pool is fill with fishes on ",
                percentFishes, " percent");
    }

}
